package com.zk.service.impl;

import com.zk.po.User;
import com.zk.dao.UserMapper;
import com.zk.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author kun
 * @since 2022-06-08
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {


    @Resource
    private UserMapper userMapper;


    //注册用户
    @Override
    public boolean addUser(String nickname, String username, String password, String email) {
        return userMapper.addUser(nickname, username, password, email) && userMapper.findUserByUsername(username) != null;
    }

    //登录用户
    @Override
    public User loginUser(String username, String password) {
        try {
            return userMapper.loginUser(username, password);

        } catch (Exception e) {
            return null;
        }
    }


    //获取用户信息
    @Override
    public User getUserData(String id) {
        return userMapper.findUserById(id);
    }


    //根据用户名查用户
    @Override
    public User findUserByUsername(String username) {
        return userMapper.findUserByUsername(username);
    }

    //根据昵称查用户
    @Override
    public User findUserByNickname(String nickname) {
        return userMapper.findUserByNickname(nickname);
    }
}


